package com.easidea.tim.dao.finance;

import java.util.Date;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springside.core.dao.extend.HibernateEntityExtendDao;

import com.easidea.tim.entity.finance.DueFrom;
import com.easidea.tim.entity.finance.DueFromSummary;
import com.easidea.tim.entity.saleorder.SaleOrder;


public class DueFromDao extends HibernateEntityExtendDao<DueFrom> {
 public DueFrom getDueFromBySalesOrderId(long orderId) {
	  Criteria ca =  this.createUnDeletedCriteria();
	  ca.add(Restrictions.eq("order.id", orderId));
	  return (DueFrom)ca.uniqueResult();	 
 }
 
 /**
	 * 更新单笔销售订单应收金额数据
	 * @param summary
	 * @param saleOrder
	 */
 public  void saveDueFrom(DueFromSummary summary,SaleOrder saleOrder) {
		DueFrom from = null;
		from = getDueFromBySalesOrderId(saleOrder.getId());
		if(from == null) {
			from = new DueFrom();
			
		}
		from.setModifyTime(new Date());
		from.setAmount(saleOrder.getMoneyNum().doubleValue());
		from.setDueFromSummary(summary);
		from.setOrder(saleOrder);
		getHibernateTemplate().saveOrUpdate(from);
	}
}
